package logic

import (
	"context"
	"shop/models/mysql"

	"shop/shoprpc/internal/svc"
	"shop/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAddLogic {
	return &OrderAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderAddLogic) OrderAdd(in *shoprpc.OrderAddRequest) (*shoprpc.OrderAddResponse, error) {
	// todo: add your logic here and delete this line
	order := mysql.Order{
		UserId:   int(in.UserId),
		Status:   int(in.Status),
		PayTypes: int(in.PayTypes),
		Price:    float64(in.Price),
		Total:    float64(in.Total),
		Number:   int(in.Number),
	}
	mysql.DB.Debug().Create(&order)
	return &shoprpc.OrderAddResponse{
		Id: int64(order.ID),
	}, nil
}
